import {OrderItemModel} from "./declare"
import {observable, action} from "mobx"
import {getUserId} from '@/utils/utils';
import {ORDER_STATUS, ORDER_TYPE, ORDER_TAB_STATUS} from '@/utils/constants';
import {network} from "@/utils/network"

/**
 * 订单详情model
 */
class OrderDetailModel {

  @observable.ref
  orderDetail: Object
  ORDER_STATUS: Object
  ORDER_TYPE: Object
  ORDER_TAB_STATUS: Object
  id: number

  hooks: Array<(cart: OrderItemModel) => void>

  constructor() {
    this.orderDetail = {}
    this.hooks = []
    this.ORDER_STATUS = ORDER_STATUS;
    this.ORDER_TYPE = ORDER_TYPE;
    this.ORDER_TAB_STATUS = ORDER_TAB_STATUS

  }

  @action
  setValue(detail) {
    detail.order_goods_number = detail.order_goods.length;

    this.orderDetail = detail
  }

  setId(key) {
    this.id = key;
  }

  getData() {
    const params = {
      user_id: getUserId()
    }
    network.get('/xxm/order/detail/' + this.id, params).then((rs) => {
      this.setValue(rs.data)
    })
  }

}

export const orderDetailModel = new OrderDetailModel()
